﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Data
{
    /// <summary>
    /// XDataRow
    /// </summary>
    public class XDataRow : System.Data.DataRow
    {
        /// <summary>
        /// 
        /// </summary>
        public new XDataTable<XDataRow> Table
        {
            get { return (XDataTable<XDataRow>)base.Table; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="builder"></param>
        public XDataRow(System.Data.DataRowBuilder builder)
            : base(builder)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="columnName"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public T GetValue<T>(string columnName, System.Data.DataRowVersion version = System.Data.DataRowVersion.Current)
        {
            T value = default(T);
            if (!string.IsNullOrEmpty(columnName) && base.Table.Columns.Contains(columnName))
            {
                object obj = base[columnName, version];
                if (obj != null && obj != Convert.DBNull)
                    value = (T)obj;
            }
            return value;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="columnName"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public new object this[string columnName, System.Data.DataRowVersion version = System.Data.DataRowVersion.Current]
        {
            get
            {
                object value = null;
                if (!string.IsNullOrEmpty(columnName) && base.Table.Columns.Contains(columnName))
                {
                    value = base[columnName, version];
                }
                return value;
            }
        }

    }
}
